<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>添加权限</title>
    <link rel="stylesheet" href="/static/lib/layuiadmin/plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/static/lib/layuiadmin/css/global.css" media="all">
    <link rel="stylesheet" href="/static/lib/layuiadmin/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/static/lib/layuiadmin/css/table.css" />
</head>

<body>
<div class="admin-main">

    <div style="margin: 15px;">
        <form class="layui-form" method="post" action="/admin/product/update">
            <div class="layui-form-item">
                <label class="layui-form-label">名称</label>
                <div class="layui-input-block">
                    <input type="text" name="name" value="<{$product.name}>" required lay-verify="required" placeholder="请文章标题" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">价格</label>
                <div class="layui-input-block">
                    <input type="text" name="price" value="<{$product.price}>" required lay-verify="required" placeholder="请输入价格" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">描述</label>
                <div class="layui-input-block">
                    <input type="text" name="desc" value="<{$product.desc}>" required lay-verify="required" placeholder="请输入产品描述" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">产品主图</label>
                <div class="layui-input-block">
                    <img src="<{$product.cover}>" style="width:200px;height:200px;" id="cover-show"/>
                    <div style="margin-top: 10px;"><input type="file" name="file" class="layui-upload-file"></div>
                    <input type="hidden" value="<{$product.cover}>" id="cover"  name="cover"/>
                </div>

            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">产品分类</label>
                <div class="layui-input-block">
                    <select name="cat" lay-filter="role" >
                        <option value="0"  <{if condition="($product.cat eq 0)"}>selected<{/if}>   >根类目</option>
                        <{volist name="tree" id="item"}>
                        <option value="<{$item.id}>"  <{if condition="($product.cat eq $item.id)"}>selected<{/if}>   ><{$item.name}></option>
                        <{if condition="(isset($item.sub))"}>
                        <{volist name="$item.sub" id="v"}>
                        <option value="<{$v.id}>" <{if condition="($product.cat eq $v.id)"}>selected<{/if}>  >|--<{$v.name}></option>
                        <{/volist}>
                        <{/if}>
                        <{/volist}>
                    </select>
                </div>

            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">产品详情</label>
                <div class="layui-input-block" >
                    <script id="container" name="content" type="text/plain" style="height:500px;">
                        <{$product.productData.content}>
                    </script>
                </div>
            </div>

            <input type="hidden" name="id" value="<{$product.id}>" />


            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button lay-filter="add" lay-submit class="layui-btn">提交</button><a href="/admin/product/index" class="layui-btn layui-btn-danger">返回</a>
                </div>
            </div>
        </form>
    </div>

</div>
<script type="text/javascript" src="/static/lib/layuiadmin/plugins/layui/layui.js"></script>

<script type="text/javascript" src="/static/lib/ueditor/ueditor.config.js?v=1"></script>
<script type="text/javascript" src="/static/lib/ueditor/ueditor.all.js"></script>
<script type="text/javascript">
    var ue = UE.getEditor('container');
</script>

<script type="text/javascript">
    layui.use('form', function(){
        var form = layui.form();
    });
    layui.use(["layer","upload"],function(){
        var $ = layui.jquery;
        layui.upload({
            url: '/admin/upload/upload'
            ,success: function(res){
                console.log(res); //上传成功返回值，必须为json格式
                if(1 == res.code){
                    $("#cover-show").attr("src",res.data.src);
                    $("#cover").val(res.data.src);
                }else{
                    layer.msg(res.msg);
                }
            }
        });
    });

</script>

</body>

</html>